//! 提供了开发工具宏
//!
//! 用于快速创建 sgs_core::card::Card 类型
//!
//!

/// 生成 Card 的声明宏
#[macro_export]
macro_rules! create_card {

    ($text:expr) => {{
        match ::sgs_core::card::Card::try_from($text) {
            Ok(_v) => _v,
            Err(_e) => panic!("{}", _e),
        }
    }};

    ($sp:expr => $text:expr) => {{
        match ::sgs_core::card::Card::try_from(($text, $sp)) {
            Ok(_v) => _v,
            Err(_e) => panic!("{}", _e),
        }
    }};

    ($($text:expr),+ $(,)?) => {{
        vec![$(create_card!($text)),+]
    }};

    (@split $sp:expr, $($text:expr),+ $(,)?) => {{
        vec![$(create_card!($sp => $text)),+]
    }};


    ($($sp:expr => $text:expr),+ $(,)?) => {{
        vec![$(create_card!($sp => $text)),+]
    }};

}

#[cfg(test)]
mod test {

    use sgs_core::card::*;
    #[test]
    fn test_create_card_macro() {
        let card = create_card!("/" => "杀/红桃/10/基本");
        let want = Card {
            color: Color::Heart,
            point: Point::P10,
            kind: Kind::Basic,
            name: "杀".to_owned(),
        };

        assert_eq!(want, card.clone());
        let card_list = create_card!("杀/红桃/10/基本", "杀/红桃/10/基本");

        assert_eq!(card_list, vec![card.clone(), card.clone()]);
    }
}
